package easier.recycler;

import androidx.annotation.NonNull;
import java.util.List;

/**
 * 接近无限数量的adapter
 */
public class InfiniteAdapter extends MultiTypeAdapter {


    public InfiniteAdapter() {

    }

    public InfiniteAdapter( List< TypeViewHolder > viewHolders ) {

        super( viewHolders );
    }

    @Override
    public void onBindViewHolder( @NonNull MultiTypeHolder holder, int position ) {

        super.onBindViewHolder( holder, convertInfinitePosition( position ) );
    }

    @Override
    public void onBindViewHolder( @NonNull MultiTypeHolder holder, int position, @NonNull List< Object > payloads ) {

        super.onBindViewHolder( holder, convertInfinitePosition( position ), payloads );
    }

    @Override
    public int getItemViewType( int position ) {

        return super.getItemViewType( convertInfinitePosition( position ) );
    }

    @Override
    public int getItemCount() {

        return Integer.MAX_VALUE;
    }

    public int convertInfinitePosition( int position ) {

        int size = mViewHolders.size();
        return position % size;
    }
}